{% extends "layout/basic.html" %}
{% load static %}

{% block title %} 用户登陆 {% endblock %}
{% block css %}
    <link rel="stylesheet" href="{% static 'web/css/account.css' %}">
    <style>
        .error-msg {
            color: red;
            position: absolute;
            font-size: 13px;
        }
    </style>
{% endblock %}


{% block content %}
    <div class="account">
        <h1 style="text-align: center">用户登陆</h1>
        <form method="POST" novalidate>
            {% csrf_token %}
            {% for field in form %}
                {% if field.name == 'code' %}
                    <div class="form-group">
                        <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                        <div class="clearfix">
                            <div class="col-md-6" style="padding-left: 0px">{{ field }}
                                <span class="error-msg">{{ field.errors.0 }}</span>
                            </div>
                            <div class="col-md-6"><img src="{% url 'image_code' %}" title="点击更换图片" id="imageCode"></div>
                        </div>
                    </div>
                {% else %}
                    <div class="form-group">
                        <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                        {{ field }}
                        <span class="error-msg">{{ field.errors.0 }}</span>
                    </div>
                {% endif %}
            {% endfor %}
            <div>
                <div style="float:right">
                    <a href="{% url 'login_sms' %}">短信验证码登陆？</a>
                </div>
            </div>
            <input type="submit" class="btn btn-primary" value="登  陆">
        </form>
    </div>
{% endblock %}


{% block js %}
    <script>
        $(function () {
            $('#imageCode').click(function () {
                var oldSrc = $(this).attr('src');
                $(this).attr('src', oldSrc + "?")
            })
        })
    </script>
{% endblock %}
